<?php
/**
 * @author kevin
 * @date 2016-03-13 14:00:00
 * @desc 留言管理
 */

if (!defined('IN_ECS'))
{
    die('Hacking attempt');
}
$version = '1.0';   //版本号

if ($_POST['api_version'] != $version)      //网店的接口版本低
{
	api_err('0x008', 'a low version api');
}
if(empty($_POST['st'])){
	api_err('0x008', 'param st is Missing');
}
//用户ID检测
if(!isset($GLOBALS['uid'])){
	api_err('0x015', 'You have not logged on');
}
$user_id = $GLOBALS['uid'];
//添加留言
if($_POST['st'] == 'add'){
	$user_info = get_profile($user_id);
	$msg_content = isset($_POST['msg_content']) ? trim($_POST['msg_content']) : '';
	$contact = isset($_POST['contact']) ? trim($_POST['contact']) : '';
	if(empty($msg_content)){
		api_err('0x008', 'Param msg_content can not empty');
	}
	$message = array(
        'user_id'     => $user_id,
        'user_name'   => $user_info['user_name'],
        'user_email'  => empty($contact)?$user_info['email']:$contact,
        'msg_type'    => 0,
        'msg_title'   => isset($_POST['msg_title']) ? trim($_POST['msg_title']) : '会员留言',
        'msg_content' => $msg_content
     );
    if (!add_message($message)){
        api_err('0x008', 'Message saved fail');
    }
	$data = array();
}
//查看留言
//st参数错误
if(!isset($data)){
	api_err('0x008');
}
data_back($data, '', RETURN_TYPE);  //返回数据

